import type HttpRequest from '@candy/framework/http/HttpRequest';
import type View from '@candy/template/View';
import Controller from '@candy/framework/web/Controller';
import HttpResponse from '@candy/framework/http/HttpResponse';

export default class IndexController extends Controller {
    public override async run(_request: HttpRequest): Promise<HttpResponse> {
        const view = this.getView() as View;
        view.enableLayout = true;
        view.layout = 'app/views/layout';
        view.cache = false;

        const posts = [
            { id: 1, title: 'hello first post' },
            { id: 2, title: 'second post' },
        ];

        const html = await this.render('home', {
            posts,
        });

        return HttpResponse.fromHTML(html);
    }
}
